Skip to content

Sheffield | 26-ITP-Jan | Mona -Eltantawy | Sprint 1 | Data- Groups/sprint 1#1076

Open
Mona-Eltantawy wants to merge 9 commits intoCodeYourFuture:mainfrom
Mona-Eltantawy:Module--Data-groups/Sprint-1
Open

Sheffield | 26-ITP-Jan | Mona -Eltantawy | Sprint 1 | Data- Groups/sprint 1#1076
Mona-Eltantawy wants to merge 9 commits intoCodeYourFuture:mainfrom
Mona-Eltantawy:Module--Data-groups/Sprint-1

Conversation

@Mona-Eltantawy
Copy link

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

@Mona-Eltantawy Mona-Eltantawy added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Mar 23, 2026
Copy link
Contributor

@cjyuan cjyuan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is another file in refractor that needs to be updated.

Comment on lines +20 to +21
// Sort without mutating original array
const sorted = [...numbers].sort((a, b) => a - b);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why make a copy of numbers before sorting?

Comment on lines +3 to +4
.filter((item) => typeof item === "number")
.reduce((acc, num) => (num > acc ? num : acc), -Infinity);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does your function return the value you expected from the following function calls?

findMax([NaN])
findMax([0, NaN, 1])

Comment on lines +54 to +62
test("array with non-number values, ignores non-numeric and returns max number", () => {
expect(findMax(["hey", 10, "hi", 60, 10])).toBe(60);
});
// Given an array with only non-number values
// When passed to the max function
// Then it should return the least surprising value given how it behaves for all other inputs
test("array with only non-number values, returns -Infinity", () => {
expect(findMax(["a", "b", null, {}])).toBe(-Infinity);
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When a string representing a valid numeric literal (for example, "300") is compared to a number,
JavaScript first converts the string into its numeric equivalent before performing the comparison.
As a result, the expression 20 < "300" evaluates to true.

To test if the function can correctly ignore non-numeric values,
consider including a string such as "300" in the relevant test cases.

Comment on lines +38 to +40
test("given an array with decimal/float number, returns the correct total sum", () => {
expect(sum([1, 2, 3, 1.5, 2.1])).toEqual(9.6);
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Decimal numbers in most programming languages (including JS) are internally represented in "floating point number" format. Floating point arithmetic is not exact. For example, the result of 46.5678 - 46 === 0.5678 is false because 46.5678 - 46 only yield a value that is very close to 0.5678. Even changing the order in which the program add/subtract numbers can yield different values.

So the following could happen

  expect( 1.2 + 0.6 + 0.005 ).toEqual( 1.805 );                // This fail
  expect( 1.2 + 0.6 + 0.005 ).toEqual( 1.8049999999999997 );   // This pass
  expect( 0.005 + 0.6 + 1.2 ).toEqual( 1.8049999999999997 );   // This fail

  console.log(1.2 + 0.6 + 0.005 == 1.805);  // false
  console.log(1.2 + 0.6 + 0.005 == 0.005 + 0.6 + 1.2); // false

Can you find a more appropriate way to test a value (that involves decimal number calculations) for equality?

Suggestion: Look up

  • Checking equality in floating point arithmetic in JavaScript
  • Checking equality in floating point arithmetic with Jest

@cjyuan cjyuan added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Reviewed Volunteer to add when completing a review with trainee action still to take.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants